package com.yunkeji.api.banner.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.enums.app.EnableEnum;
import com.yunkeji.common.utils.ServletUtils;
import com.yunkeji.dao.domain.sys.Banner;
import com.yunkeji.dao.mapper.sys.BannerMapper;
import com.yunkeji.dao.vo.sys.SysBannerVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * banner相关接口
 *
 * @author 雷擎宇
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/banner")
public class BannerController extends BaseController {

    private final BannerMapper baseMapper;

    /** 获取banner */
    @PostMapping()
    public R<List<SysBannerVo>> getProvince() {
        String branch = ServletUtils.getRequest().getHeader("branch");
        branch = String.valueOf(branch.charAt(0));
        List<SysBannerVo> banners = baseMapper.selectVoList(Wrappers.lambdaQuery(Banner.class)
            .eq(Banner::getEnable, EnableEnum.YES.getCode())
            .eq(Banner::getBranch, Integer.parseInt(branch))
            .orderByAsc(Banner::getSort));
        return R.ok(banners);
    }
}
